/**
 * @ author: 汪孟苹
 */
define(["jquery"],function($){
	var servers = {};

	servers.getPageActive = function(options){
		if( options.pageClick == "上页" ){
			if( options.page > 1 ) options.page --;
		}else if( options.pageClick == "下页" ){
			if( options.page < options.pagesAll ) options.page ++;
		}else{
			options.page = options.pageClick;
		}
		return options.page;
	}

	var createPageObj = function(i,page){
		var obj = {};
		obj.page = i + 1;
		obj.active = page;
		return obj;
	};
	/* 翻页数据处理 */
	servers.pageDataHandle = function(pagesAll,page){
		var arr = [], arr1 = [], arr2 = [], arr3 = [];
		var objprev = {
			"page": "上页",
			"active": page
		}
		var objnext = {
			"page": '下页',
			"active": page
		}
		if(page == 1){	// 如果是第一页，首页不可点击
			objprev.disabled = true;
			if(page == pagesAll){    // 如果只有一页，首页和尾页都不可点击
				objnext.disabled = true;
			}
		}else if(page == pagesAll){    // 如果是最后一页，尾页不可点击
			objnext.disabled = true;
		}

		arr1.push(objprev);
		if(pagesAll <= 5){
			for(var i = 0; i < pagesAll; i++){
				arr1.push( createPageObj(i,page) );
			}			
			arr1.push(objnext);
			arr = [arr1];
		}else{
			if(page <= 3){
				for(var i = 0; i < 4; i++){
					arr1.push( createPageObj(i,page) );
				}
				for(i = pagesAll - 1; i < pagesAll; i++){
					arr2.push( createPageObj(i,page) );
				}
				arr2.push(objnext);
				arr = [arr1,arr2];
			}else if(page >= pagesAll - 2){
				for(var i = 0; i < 1; i++){
					arr1.push( createPageObj(i,page) );
				}
				for(i = pagesAll - 4; i < pagesAll; i++){
					arr2.push( createPageObj(i,page) );
				}
				arr2.push(objnext);
				arr = [arr1,arr2];
			}else{
				for(var i = 0; i < 1; i++){
					arr1.push( createPageObj(i,page) );
				}
				for(var i = page-2; i <= page; i++){
					arr2.push( createPageObj(i,page) );
				}
				for(var i = pagesAll-1; i < pagesAll; i++){
					arr3.push( createPageObj(i,page) );
				}
				arr3.push(objnext);
				arr = [arr1,arr2,arr3];
			};
		};
		return arr;
	};

	return servers;
});
